diff -Naur svnsrc/main/java/org/jboss/ws/integration/other/ContextServlet.java src/main/java/org/jboss/ws/integration/other/ContextServlet.java
--- svnsrc/main/java/org/jboss/ws/integration/other/ContextServlet.java	2006-08-30 17:16:35.918669898 +0200
+++ src/main/java/org/jboss/ws/integration/other/ContextServlet.java	2006-08-30 15:24:11.707800452 +0200
@@ -89,11 +89,16 @@
       PrintWriter writer = res.getWriter();
       res.setContentType("text/html");
 
+      URL requestURL = new URL(req.getRequestURL().toString());
+      String urlString = requestURL.toExternalForm();
+      String requestURI = requestURL.getPath();
+      String hostPath = urlString.substring(0, urlString.indexOf(requestURI));
+      
       writer.print("<html>");
       setupHTMLResponseHeader(writer);
 
       writer.print("<body>");
-      writer.print(epManager.showServiceEndpointTable());
+      writer.print(epManager.showServiceEndpointTable(hostPath));
       writer.print("</body>");
       writer.print("</html>");
       writer.close();
diff -Naur svnsrc/main/java/org/jboss/ws/server/ContextServlet.java src/main/java/org/jboss/ws/server/ContextServlet.java
--- svnsrc/main/java/org/jboss/ws/server/ContextServlet.java	2006-08-30 17:16:39.850930448 +0200
+++ src/main/java/org/jboss/ws/server/ContextServlet.java	2006-08-30 15:23:01.199128568 +0200
@@ -25,6 +25,7 @@
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.net.URL;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -66,11 +67,16 @@
       PrintWriter writer = res.getWriter();
       res.setContentType("text/html");
 
+      URL requestURL = new URL(req.getRequestURL().toString());
+      String urlString = requestURL.toExternalForm();
+      String requestURI = requestURL.getPath();
+      String hostPath = urlString.substring(0, urlString.indexOf(requestURI));
+      
       writer.print("<html>");
       setupHTMLResponseHeader(writer);
 
       writer.print("<body>");
-      writer.print(epManager.showServiceEndpointTable());
+      writer.print(epManager.showServiceEndpointTable(hostPath));
       writer.print("</body>");
       writer.print("</html>");
       writer.close();
diff -Naur svnsrc/main/java/org/jboss/ws/server/ServiceEndpoint.java src/main/java/org/jboss/ws/server/ServiceEndpoint.java
--- svnsrc/main/java/org/jboss/ws/server/ServiceEndpoint.java	2006-08-30 17:16:39.846930183 +0200
+++ src/main/java/org/jboss/ws/server/ServiceEndpoint.java	2006-08-30 15:18:58.119022151 +0200
@@ -123,7 +123,7 @@
 
    /** Handle a WSDL request or a request for an included resource
     */
-   public void handleWSDLRequest(OutputStream outStream, URL requestURL, String resourcePath) throws IOException
+   public void handleWSDLRequest(OutputStream outStream, URL requestURL, String resourcePath, boolean rewrite) throws IOException
    {
       ServiceEndpointInfo sepInfo = getServiceEndpointInfo();
       EndpointMetaData epMetaData = sepInfo.getServerEndpointMetaData();
@@ -133,7 +133,7 @@
       String hostPath = urlString.substring(0, urlString.indexOf(requestURI));
 
       WSDLRequestHandler wsdlRequestHandler = new WSDLRequestHandler(epMetaData);
-      Document document = wsdlRequestHandler.getDocumentForPath(hostPath, requestURI, resourcePath);
+      Document document = wsdlRequestHandler.getDocumentForPath(hostPath, requestURI, resourcePath, rewrite);
 
       OutputStreamWriter writer = new OutputStreamWriter(outStream);
       new DOMWriter(writer).setPrettyprint(true).print(document.getDocumentElement());
diff -Naur svnsrc/main/java/org/jboss/ws/server/ServiceEndpointManager.java src/main/java/org/jboss/ws/server/ServiceEndpointManager.java
--- svnsrc/main/java/org/jboss/ws/server/ServiceEndpointManager.java	2006-08-30 17:16:39.854930714 +0200
+++ src/main/java/org/jboss/ws/server/ServiceEndpointManager.java	2006-08-30 15:17:47.262327207 +0200
@@ -90,6 +90,8 @@
    private int webServiceSecurePort;
    // Whether we should always modify the soap address to the deployed endpoing location
    private boolean alwaysModifySOAPAddress;
+   // Whether we should always rewrite the soap address modifying standard hostname with the one used in the call by the client 
+   private boolean rewriteSOAPAddressWithCalledHost;
    // The name of the invoker that handles invocations on JSE endpoints
    private String serviceEndpointInvokerJSE;
    // The name of the invoker that handles invocations on EJB2.1 endpoints
@@ -118,6 +120,10 @@
    {
       return alwaysModifySOAPAddress;
    }
+   
+   public boolean isRewriteSOAPAddressWithCalledHost() {
+		return rewriteSOAPAddressWithCalledHost;
+   }
 
    public void setWebServiceHost(String host)
    {
@@ -151,6 +157,9 @@
    {
       this.alwaysModifySOAPAddress = modify;
    }
+   public void setRewriteSOAPAddressWithCalledHost(boolean rewrite) {
+	   this.rewriteSOAPAddressWithCalledHost = rewrite;
+   }
 
    public String getServiceEndpointInvokerEJB21()
    {
@@ -256,7 +265,7 @@
 
    /** Show the registered webservices
     */
-   public String showServiceEndpointTable()
+   public String showServiceEndpointTable(String hostPath)
    {
       StringWriter sw = new StringWriter();
       PrintWriter pw = new PrintWriter(sw);
@@ -273,6 +282,27 @@
          ServiceEndpoint wsEndpoint = (ServiceEndpoint)entry.getValue();
          ServiceEndpointInfo seInfo = wsEndpoint.getServiceEndpointInfo();
          String endpointAddress = seInfo.getServerEndpointMetaData().getEndpointAddress();
+         
+         if (this.isRewriteSOAPAddressWithCalledHost()) {
+        	 int toend = -1;
+        	 StringBuffer newLocation = new StringBuffer();
+     		if (endpointAddress.startsWith("http://")) {
+     			
+     			newLocation.append(hostPath);
+     			toend = endpointAddress.substring(7).indexOf("/")+7;
+     			
+     		}
+     		if (endpointAddress.startsWith("https://")) {
+     			
+     			newLocation.append(hostPath);
+     			toend = endpointAddress.substring(8).indexOf("/")+8;
+     		}
+     		if (toend != -1 ) {
+     			newLocation.append(endpointAddress.substring(toend));
+     		}
+     		endpointAddress = newLocation.toString();
+         }
+         
          pw.println("<tr><td>" + sepID.getCanonicalName() + "</td><td><a href='" + endpointAddress + "?wsdl'>" + endpointAddress + "?wsdl</a></td></tr>");
       }
       pw.println("</table>");
@@ -280,7 +310,6 @@
 
       return sw.toString();
    }
-
    /** Get the endpoint metrics
     */
    public ServiceEndpointMetrics getServiceEndpointMetrics(ObjectName sepID)
@@ -324,7 +353,7 @@
       if (wsEndpoint == null)
          throw new WSException("Cannot obtain endpoint for: " + sepID);
       
-      wsEndpoint.handleWSDLRequest(outStream, requestURL, resourcePath);
+      wsEndpoint.handleWSDLRequest(outStream, requestURL, resourcePath, this.rewriteSOAPAddressWithCalledHost);
    }
 
    public void processSOAPRequest(ObjectName sepID, InputStream inStream, OutputStream outStream, Object context) throws Exception
diff -Naur svnsrc/main/java/org/jboss/ws/server/ServiceEndpointManagerMBean.java src/main/java/org/jboss/ws/server/ServiceEndpointManagerMBean.java
--- svnsrc/main/java/org/jboss/ws/server/ServiceEndpointManagerMBean.java	2006-08-30 17:16:39.846930183 +0200
+++ src/main/java/org/jboss/ws/server/ServiceEndpointManagerMBean.java	2006-08-30 15:12:34.449600327 +0200
@@ -48,6 +48,9 @@
 
    boolean isAlwaysModifySOAPAddress();
    void setAlwaysModifySOAPAddress(boolean modify);
+   
+   public boolean isRewriteSOAPAddressWithCalledHost();
+   public void setRewriteSOAPAddressWithCalledHost(boolean rewrite);
 
    List<HandlerInfo> getHandlerInfos(ObjectName sepID);
    void setHandlerInfos(ObjectName sepID, List<HandlerInfo> infos);
diff -Naur svnsrc/main/java/org/jboss/ws/server/WSDLRequestHandler.java src/main/java/org/jboss/ws/server/WSDLRequestHandler.java
--- svnsrc/main/java/org/jboss/ws/server/WSDLRequestHandler.java	2006-08-30 17:16:39.850930448 +0200
+++ src/main/java/org/jboss/ws/server/WSDLRequestHandler.java	2006-08-30 15:21:23.728670204 +0200
@@ -67,7 +67,7 @@
     * @param resourcePath The wsdl resource to get, can be null for the top level wsdl
     * @return A wsdl document, or null if it cannot be found
     */
-   public Document getDocumentForPath(String hostPath, String requestURI, String resourcePath) throws IOException
+   public Document getDocumentForPath(String hostPath, String requestURI, String resourcePath, boolean rewrite) throws IOException
    {
       String wsdlLocation = epMetaData.getServiceMetaData().getWsdlFile();
       if (wsdlLocation == null)
@@ -94,7 +94,9 @@
          Element wsdlElement = DOMUtils.parse(resFile.toURL().openStream());
          wsdlDoc = wsdlElement.getOwnerDocument();
       }
-
+      if (rewrite) {
+    	  rewriteSOAPAddress(hostPath,  wsdlDoc.getDocumentElement());
+      }
       modifyImportLocations(hostPath, requestURI, resourcePath, wsdlDoc.getDocumentElement());
       return wsdlDoc;
    }
@@ -144,5 +146,67 @@
          }
       }
    }
+   /**
+    * rewrite the SOAP address using hostname get from invocation URL
+    */
+   private void rewriteSOAPAddress(String hostPath, Element element) {
+	  
+      NodeList wsdlnlist = element.getChildNodes();
+      for (int i = 0; i < wsdlnlist.getLength(); i++) {
+         Node wsdlChildNode = wsdlnlist.item(i);
+         if (wsdlChildNode.getNodeType() == Node.ELEMENT_NODE) {
+            Element wsdlChildElement = (Element)wsdlChildNode;
+            String wsdlChildNodeName = wsdlChildElement.getLocalName();
+            if ("service".equals(wsdlChildNodeName)) {
+            	//now searching for port...
+            	NodeList servicenlist = wsdlChildElement.getChildNodes();
+            	for (int j = 0; j < servicenlist.getLength(); j++) {
+                    Node serviceChildNode = servicenlist.item(j);
+                    if (serviceChildNode.getNodeType() == Node.ELEMENT_NODE) {
+                       Element serviceChildElement = (Element)serviceChildNode;
+                       String serviceChildNodeName = serviceChildElement.getLocalName();
+                       if ("port".equals(serviceChildNodeName)) {
+                    	   //now searching for soap:address...
+                    	   NodeList portnlist = serviceChildElement.getChildNodes();
+                    	   for (int k = 0; k < portnlist.getLength(); k++) {
+                    	         Node portChildNode = portnlist.item(k);
+                    	         if (portChildNode.getNodeType() == Node.ELEMENT_NODE) {
+                    	            Element portChildElement = (Element)portChildNode;
+                    	            String portChildNodeName = portChildElement.getNodeName();
+                    	            if ("soap:address".equals(portChildNodeName)) {
+                    	            	//found, let's rewrite...
+                    	            	Attr locationAttr = portChildElement.getAttributeNode("location");
+                    	            	
+                    	            	if (locationAttr != null) {
+                    	            		int toend = -1;
+                    	            		String orgLocation = locationAttr.getNodeValue();
+                    	            		StringBuffer newLocation = new StringBuffer();
+                    	            		if (orgLocation.startsWith("http://")) {
+                    	            			
+                    	            			newLocation.append(hostPath);
+                    	            			toend = orgLocation.substring(7).indexOf("/")+7;
+                    	            			
+                    	            		}
+                    	            		if (orgLocation.startsWith("https://")) {
+                    	            			
+                    	            			newLocation.append(hostPath);
+                    	            			toend = orgLocation.substring(8).indexOf("/")+8;
+                    	            		}
+                    	            		if (toend != -1 ) {
+                    	            			newLocation.append(orgLocation.substring(toend));
+                    	            		}
+                    	            		locationAttr.setNodeValue(newLocation.toString());
+                    	            	}
+                    	            	
+                    	            }
+                    	         }
+                    	   }
+                       }
+                    }
+            	}
+            }
+         }
+      }
+   }
 
 }
diff -Naur svnsrc/main/resources/jbossws.beans/META-INF/jboss-beans.xml src/main/resources/jbossws.beans/META-INF/jboss-beans.xml
--- svnsrc/main/resources/jbossws.beans/META-INF/jboss-beans.xml	2006-08-30 17:16:43.443168469 +0200
+++ src/main/resources/jbossws.beans/META-INF/jboss-beans.xml	2006-08-30 15:11:00.651385284 +0200
@@ -15,7 +15,8 @@
       <property name="webServiceHost">${jboss.bind.address}</property>
       <property name="webServiceSecurePort">8443</property>
       <property name="webServicePort">8080</property>
-      <property name="alwaysModifySOAPAddress">true</property>
+      <property name="alwaysModifySOAPAddress">true</property>
+      <property name="rewriteSOAPAddressWithCalledHost">true</property>
       
       <property name="serviceEndpointInvokerJSE">org.jboss.ws.server.ServiceEndpointInvokerJSE</property>
       <property name="serviceEndpointInvokerEJB21">org.jboss.ws.integration.jboss.ServiceEndpointInvokerEJB21</property>
